package ui;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class ImagePanel extends JPanel
{
	private BufferedImage image;

	public ImagePanel(String imagePath) 
	{
		//TODO: consider making this throw exceptions instead of handling them.
		try {                
			image = ImageIO.read(new File(imagePath));
		} catch (IOException ex) {
	        System.err.println("Image '" + imagePath + "' could not be read.");
		}
	}
	
	public void changeImage(String imagePath)
	{
		System.out.println("From ui\\ImagePanel: Changing to '" + imagePath + "'.");
		try{
			image = ImageIO.read(new File(imagePath));
		} catch (IOException ex) {
			System.err.println("Image '" + imagePath + "' could not be read.");
		}
		this.repaint();
		//like srsly considering making it throw exceptions, for stack traces
	}
	
	@Override
    protected void paintComponent(Graphics g) 
	{
        super.paintComponent(g);
        g.drawImage(image, 0, 0, null); // see javadoc for more info on the parameters            
    }

}
